<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
	<div data-options="region:'south',split:true" style="width: 100%;height: 190px">
		<form id="form" method="post">
			<table class="detailTable" style="width: 98%">
				<tr>
					<th style="width: 20px;">发布人:</th>
					<td><input style="width:80%;height:10px; border: 0px;outline:none;cursor: pointer;" name="createUser" readonly="readonly" value="<%=request.getParameter("createUser")%> + <%=request.getParameter("userName")%>"></td>				</tr>
				<tr>
					<th style="width: 120px;">回复内容:</th>
					<td><textarea style="width:80%;height:70px;" name="replyContent" id="reply_replyContent"></textarea></td>
				</tr>
				<tr>
					<td align="right" colspan="4">
						<input type="hidden" name="complaintId" value="<%=request.getParameter("complaintId")%>">
						<input type="button" onclick="submitForm()" class="button" value="提交">
						<input type="button" onclick="pms.resetForm('form')" class="button" value="重置">
					</td>
				</tr>
				</table>
		</form>
		
	</div>
</div>
<script>
function submitForm() {
	url = '<c:url value="/complaint/insertEmBReply.do"/>';

	$('#form').form('submit', {
		url : url,
		onSubmit : function(param) {
			if (!$("#form").form('validate')) {
				return false;
			}
		},
		success : function(data) {
			var ret = eval("(" + data + ")");
			if (ret.code=="200") {
				alertShow("回复成功");
				$("#reply_replyContent").val("");
				tbl.refresh();
			} else {
				alertError(ret.result);
			}
		}
	});
}

function deleteRecord(replyId,i){
	if(confirm("确定删除记录?")){
		var param = {"replyId":replyId};
		console.log(param);
		$.pmsAjax({
			url:'<c:url value="/complaint/deleteEmBReply.do"/>',
			data:param,
			success:function(data){
				if(data.code==200){
					alertShow("删除记录成功");
					/*
					疑问：tbl.removeRow(i)；没有调用成功，目前只能整个页面刷新
					*/
					//tbl.removeRow(i);
					initList();
					
				}else{
					alertError(data.result);
				}
			}
		});
	}
}

var tbl;
$(function(){
	initList();
});

function initList(){
	tbl = $('#tableGrid').pDataGrid({
		 columns:[[
				  {field:'replyContent',title:'回复内容',width:'300',sortable:true},
				  {field:'replyUser',title:'回复人员',width:'70',sortable:true},
                  {
                      field: 'replyDate', title: '回复时间', width: 100,sortable: true,
                      formatter : function(value){
                          var date = new Date(value);
                          var y = date.getFullYear();
                          var m = date.getMonth() + 1;
                          var d = date.getDate();
                          return y + '-' +m + '-' + d;
                      }
                  },
				  {
						title : '操作',
						field : 'action',
						width : '30',
						align : 'center',
						formatter : function(value, row, index) {
							var str = '';
								str += ' <img class="iconImg ext-icon-note_delete" title="删除" onclick="deleteRecord('+row.replyId+',' + index + ');"/>';
							return str;
						}
					} 
				  ]
			  ],
		    url:'<c:url value="/complaint/searchPageEmBReply.do"/>',  
		    pagination:true,
		    pageSize:10,
		    fitColumns:false,
		    singleSelect:false,
		    queryParams:{
		    	"complaintId":'<%=request.getParameter("complaintId")%>'
		    },
		    completeCallback:function(data){
				if(data.code == "100"){
					alertError(data.result);
				} 
				
			}
	}); 
}
</script>
